package com.wys.singleton_demo.hungry;

import java.io.Serializable;

/**
 * @author godShan
 * @Description: 饿汉式单例
 * @date 2019/5/5 11:05
 */
public class HungrySingleton implements Serializable {

    private static final HungrySingleton INSTANCE = new HungrySingleton();

    private HungrySingleton() {

        if (INSTANCE != null) {
            throw new RuntimeException("不允许创建实例");
        }

    }

    public static HungrySingleton getInstance() {
        return INSTANCE;
    }

    //防止序列化 破坏单例
    private Object readResolve() {
        return INSTANCE;
    }

}
